package westh.ilib.service;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import net.sf.json.JSONArray;

import org.apache.commons.logging.Log;

public class MultiThread extends Thread {
	
	private CountDownLatch threadsSignal; 
	ResourceService service=null;
	private String inputStr="";
	private String field="";
	private Log log=null;
	private List list=null;
	public MultiThread(CountDownLatch threadsSignal,ResourceService service,String inputStr,String field,List list,Log log){
		this.threadsSignal=threadsSignal;
		this.service=service;
		this.inputStr=inputStr;
		this.field=field;
		this.list=list;
		this.log=log;
	}
	
	public void run(){
		String outString="";
		try{		
		if(field.equals("2"))
			outString=service.getRscListFromOAI(inputStr, log);
		if(field.equals("4"))
			outString=service.getRscListFromTLib(inputStr, log);
		if(field.equals("5"))
			outString=service.getRscListFromTSys(inputStr, log);
		}catch(Exception e){
			e.printStackTrace();
			log.debug("query="+inputStr);
			log.debug("field="+field);
		}
		if(!outString.equals("")){
			JSONArray jsonArray=JSONArray.fromObject(outString);
			list.add(jsonArray);
		}
		threadsSignal.countDown();
		log.debug("Finish retrieving from field "+field);
	}
	
	
	

}
